<template>
  <div class="container">
    <el-card>
      <div class="step-box">
        <div class="btnbox">
          <el-button type="primary" @click="savaAll">保存</el-button>
        </div>
        <step :step-arr="stepArr" @changeId="changeId" />
        <el-divider />
      </div>
      <el-form
        ref="ruleForm"
        class="container_form"
        :model="ruleForm"
        :rules="rulesForm"
        :validate-on-rule-change="false"
      >
        <div v-show="active === 0">
          <el-form-item label-width="120px" label="流程名称" prop="templateName">
            <el-input
              v-model="ruleForm.templateName"
              style="width: 200px;"
              :rows="10"
              :autosize="{ minRows: 5, maxRows: 8 }"
              placeholder="流程名称"
              @blur="templateNameBlur"
            />
          </el-form-item>
          <el-form-item label-width="120px" label="备注">
            <el-input
              v-model="ruleForm.remark"
              type="textarea"
              style="width: 200px"
              placeholder="备注"
              @blur="remarkBlur"
            />
          </el-form-item>
          <el-form-item label-width="120px" label="考核发起人" prop="assessment">
            <el-form-item v-show="ruleForm.assessDepartName !==''" class="item">
              <el-input
                ref="assessDepartName"
                v-model="ruleForm.assessDepartName"
                type="button"
                placeholder="选部门"
                style="width: 200px;vertical-align: middle;"
                @click.native="popUpClick(0)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(0)">删除
              </el-button>
            </el-form-item>
            <el-form-item v-show="ruleForm.assessRoleName!==''" class="item">
              <el-input
                ref="assessRoleName"
                v-model="ruleForm.assessRoleName"
                type="button"
                style="width: 200px;vertical-align: middle;"
                placeholder="选角色"
                @click.native="popUpClick(1)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(1)">删除
              </el-button>
            </el-form-item>
            <el-form-item v-show="ruleForm.assessUserName!==''" class="item">
              <el-input
                ref="assessUserName"
                v-model="ruleForm.assessUserName"
                type="button"
                style="width: 200px;vertical-align: middle;"
                placeholder="选人员"
                @click.native="popUpClick(2)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(2)">删除
              </el-button>
            </el-form-item>
            <el-button icon="el-icon-plus" size="small" type="primary" @click.native="popUpClick(0)">选部门</el-button>
            <el-button icon="el-icon-plus" size="small" type="primary" @click.native="popUpClick(1)">选角色</el-button>
            <el-button icon="el-icon-plus" size="small" type="primary" @click.native="popUpClick(2)">选人员</el-button>
          </el-form-item>

          <el-form-item label-width="120px" label="被考核人员" prop="assessed">
            <el-form-item v-show="ruleForm.beingAssessDepartName!==''" class="item">
              <el-input
                ref="beingAssessDepartName"
                v-model="ruleForm.beingAssessDepartName"
                type="button"
                placeholder="选部门"
                style="width: 200px;vertical-align: middle;"
                @click.native="popUpClick(3)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(3)">删除
              </el-button>
            </el-form-item>

            <el-form-item v-show="ruleForm.beingAssessRoleName!==''" class="item">
              <el-input
                ref="beingAssessRoleName"
                v-model="ruleForm.beingAssessRoleName"
                type="button"
                placeholder="选角色"
                style="width: 200px;vertical-align: middle;"
                @click.native="popUpClick(4)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(4)">删除
              </el-button>
            </el-form-item>

            <el-form-item v-show="ruleForm.beingAssessUserName!==''" class="item">

              <el-input
                ref="beingAssessUserName"
                v-model="ruleForm.beingAssessUserName"
                type="button"
                placeholder="选人员"
                style="width: 200px;vertical-align: middle;"
                @click.native="popUpClick(5)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(5)">删除
              </el-button>

            </el-form-item>
            <el-button icon="el-icon-plus" size="small" type="primary" @click.native="popUpClick(3)">选部门</el-button>
            <el-button icon="el-icon-plus" size="small" type="primary" @click.native="popUpClick(4)">选角色</el-button>
            <el-button icon="el-icon-plus" size="small" type="primary" @click.native="popUpClick(5)">选人员</el-button>
          </el-form-item>
          <el-form-item label-width="150px" label="是否必填审批意见" prop="isEnableCopy">
            <el-radio-group
              :key="approvalKey"
              v-model="ruleForm.isEnableOpinion"
            >
              <el-radio
                v-for="item in commentsgroup"
                :key="item.value"
                :value="item.value"
                :label="item.value"
                @click.native.prevent="changeComments(item.value)"
              >{{ item.label }}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="发起人组织架构限制">
            <el-tooltip
              class="item"
              effect="dark"
              content="开启后:考核发起人将只能考核自己组织架构下权限内的人员;关闭后:则没有限制,考核发起人可以对所有被考核人员发起考核"
              placement="top-start"
            >
              <el-switch v-model="ruleForm.isOrganization" :active-value="1" :inactive-value="0" />
            </el-tooltip>
          </el-form-item>
        </div>

        <div v-show="active === 2">
          <el-form-item label-width="120px" label="抄送" prop="isEnableCopy">
            <el-switch
              v-model="ruleForm.isEnableCopy"
              :active-value="1"
              :inactive-value="0"
              class="main-el-switch"
              :width="60"
              active-text="开"
              inactive-text="关"
            />
          </el-form-item>
          <el-form-item label-width="120px" label="抄送人" prop="cc">
            <el-form-item v-show="ruleForm.ccRole !==''" class="item">
              <el-input
                ref="ccRole"
                v-model="ruleForm.ccRole"
                type="button"
                style="width: 200px;vertical-align: middle;"
                placeholder="选角色"
                :disabled="ruleForm.isEnableCopy === 0"
                @click.native="popUpClick(6)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(6)">删除
              </el-button>
            </el-form-item>

            <el-form-item v-show="ruleForm.ccPersonnel !==''" class="item">
              <el-input
                ref="ccPersonnel"
                v-model="ruleForm.ccPersonnel"
                type="button"
                style="width: 200px;vertical-align: middle;"
                placeholder="选人员"
                :disabled="ruleForm.isEnableCopy === 0"
                @click.native="popUpClick(7)"
              >
                <i slot="suffix" style="font-size: 18px;" class="el-icon-edit-outline" />
              </el-input>
              <el-button type="danger" round size="mini" style="margin-left: 20px;" @click.native="deleteEach(7)">删除
              </el-button>
            </el-form-item>

            <el-button icon="el-icon-plus" size="small" :disabled="ruleForm.isEnableCopy === 0" type="primary" @click.native="popUpClick(6)">选角色</el-button>
            <el-button icon="el-icon-plus" size="small" :disabled="ruleForm.isEnableCopy === 0" type="primary" @click.native="popUpClick(7)">选人员</el-button>
          </el-form-item>
        </div>
      </el-form>
      <approvalnode v-show="active === 1" :active="active" />
    </el-card>
    <pop
      :poshow="popUpObj[popUpIndex].show"
      :type="popUpObj[popUpIndex].type"
      :title="popUpObj[popUpIndex].potitle"
      :echo="popUpObj[popUpIndex].commitArray"
      :index="popUpIndex"
      @handleClose="handleClose"
      @handleDetermine="handleDetermine"
    />
  </div>
</template>

<script>
import pop from './components/pop.vue'
import step from './components/step.vue'
import approvalnode from './components/approvalnode.vue'
export default {
  components: {
    pop,
    step,
    approvalnode
  },

  data() {
    const checkAssessment2 = (rule, value, callback) => {
      const Assessment1 = this.$refs.assessDepartName.value
      const Assessment2 = this.$refs.assessRoleName.value
      const Assessment3 = this.$refs.assessUserName.value
      if (Assessment1 && Assessment3 && !Assessment2) {
        callback(new Error('请选择考核角色或去除部门'))
      } else {
        callback()
      }
    }
    const checkAssessment1 = (rule, value, callback) => {
      const Assessment1 = this.$refs.assessDepartName.value
      const Assessment2 = this.$refs.assessRoleName.value
      const Assessment3 = this.$refs.assessUserName.value
      if (Assessment1 && Assessment2 && !Assessment3) {
        callback()
      } else {
        if (Assessment2 || Assessment3) {
          callback()
        } else {
          callback(new Error('请选择考核角色/人员或去除部门'))
        }
      }
    }

    const checkAssessment = (rule, value, callback) => {
      const Assessment1 = this.$refs.assessDepartName.value
      const Assessment2 = this.$refs.assessRoleName.value
      const Assessment3 = this.$refs.assessUserName.value

      if (Assessment1 || Assessment2 || Assessment3) {
        callback()
      } else {
        callback(new Error('至少选择考核角色或考核人员一项做为考核发起人'))
      }
    }
    const checkAssessed2 = (rule, value, callback) => {
      const Assessment1 = this.$refs.beingAssessDepartName.value
      const Assessment2 = this.$refs.beingAssessRoleName.value
      const Assessment3 = this.$refs.beingAssessUserName.value
      if (Assessment1 && Assessment3 && !Assessment2) {
        callback(new Error('请选择被考核角色或去除被考核部门'))
      } else {
        callback()
      }
    }

    const checkAssessed1 = (rule, value, callback) => {
      const Assessment1 = this.$refs.beingAssessDepartName.value
      const Assessment2 = this.$refs.beingAssessRoleName.value
      const Assessment3 = this.$refs.beingAssessUserName.value
      if (Assessment1 && Assessment2 && !Assessment3) {
        callback()
      } else {
        if (Assessment2 || Assessment3) {
          callback()
        } else {
          callback(new Error('请选择被考核角色/被考核人员或去除被考核部门'))
        }
      }
    }

    const checkAssessed = (rule, value, callback) => {
      const Assessment1 = this.$refs.beingAssessDepartName.value
      const Assessment2 = this.$refs.beingAssessRoleName.value
      const Assessment3 = this.$refs.beingAssessUserName.value
      if (Assessment1 || Assessment2 || Assessment3) {
        callback()
      } else {
        callback(new Error('至少选择被考核角色或被考核人员一项做为被考核人'))
      }
    }
    const checkCc = (rule, value, callback) => {
      const Assessment1 = this.$refs.ccRole.value
      const Assessment2 = this.$refs.ccPersonnel.value

      if (Assessment1 || Assessment2) {
        callback()
      } else {
        callback(new Error('至少选择一个选项作为抄送依据'))
      }
    }

    return {
      approvalKey: false,
      // 审批意见
      commentsgroup: [
        {
          value: 1,
          label: '审批意见'
        }
      ],
      checkAssessment2: checkAssessment2,
      checkAssessment1: checkAssessment1,
      checkAssessment: checkAssessment,
      checkAssessed: checkAssessed,
      checkAssessed1: checkAssessed1,
      checkAssessed2: checkAssessed2,
      checkCc: checkCc,
      labelPosition: 'left',
      stepArr: [{
        id: 0,
        text: '制定目标'
      },
      {
        id: 1,
        text: '审批节点'
      },
      {
        id: 2,
        text: '抄送'
      }
      ],
      active: 0,
      popUpObj: [{
        show: false,
        type: '1',
        potitle: '选部门',
        commitArray: []
      },
      {
        show: false,
        type: '2',
        potitle: '选角色',
        commitArray: []
      },
      {
        show: false,
        type: '3',
        potitle: '选人员',
        commitArray: []
      },
      {
        show: false,
        type: '4',
        potitle: '选部门',
        commitArray: []
      },
      {
        show: false,
        type: '5',
        potitle: '选角色',
        commitArray: []
      },
      {
        show: false,
        type: '6',
        potitle: '选人员',
        commitArray: []
      },
      {
        show: false,
        type: '9',
        potitle: '选角色',
        commitArray: []
      },
      {
        show: false,
        type: '10',
        potitle: '选人员',
        commitArray: []
      }
      ],
      popUpIndex: 0, // 点击的
      ruleForm: {
        templateName: '', // 流程名称
        flowType: 1,
        remark: '', // 备注
        assessDepartName: '', // 考核 部门
        assessRoleName: '', // 考核 角色
        assessUserName: '', // 考核 人员
        beingAssessDepartName: '', // 被考核部门
        beingAssessRoleName: '', // 被考核角色
        beingAssessUserName: '', // 被考核人员
        isEnableOpinion: 0, // 目标指定是否必填审批意见
        isEnableCopy: null, // 是否开启抄送
        ccRole: '', // 抄送角色
        ccPersonnel: '', // 抄送人员,
        isOrganization: 1 // 是否开启组织架构限制
      },
      rulesForm: {
        templateName: [{
          required: true,
          message: '请输入流程名称',
          trigger: ['blur', 'change']
        }],
        assessment: [{
          required: true,
          validator: this.checkAssessment,
          trigger: ['blur', 'change']
        },
        {
          required: true,
          validator: this.checkAssessment1,
          trigger: ['blur', 'change']
        },
        {
          required: true,
          validator: this.checkAssessment2,
          trigger: ['blur', 'change']
        }

        ],
        assessed: [
          {
            required: true,
            validator: this.checkAssessed,
            trigger: ['blur', 'change']
          },
          {
            required: true,
            validator: this.checkAssessed1,
            trigger: ['blur', 'change']
          },
          {
            required: true,
            validator: this.checkAssessed2,
            trigger: ['blur', 'change']
          }
        ],
        cc: [{
          required: true,
          validator: this.checkCc,
          trigger: ['blur', 'change']
        }]
      }
    }
  },
  computed: {},
  watch: {
    'ruleForm.isOrganization'(newval) {
      if (JSON.parse(localStorage.getItem('setTargetassignmentOBJ'))) {
        const setTargetassignmentOBJ = JSON.parse(
          localStorage.getItem('setTargetassignmentOBJ')
        )
        setTargetassignmentOBJ.ruleForm = this.ruleForm
        localStorage.setItem(
          'setTargetassignmentOBJ',
          JSON.stringify(setTargetassignmentOBJ)
        )
      }
    },
    'ruleForm.isEnableCopy'(newval) {
      if (JSON.parse(localStorage.getItem('setTargetassignmentOBJ'))) {
        const setTargetassignmentOBJ = JSON.parse(
          localStorage.getItem('setTargetassignmentOBJ')
        )
        setTargetassignmentOBJ.ruleForm = this.ruleForm
        localStorage.setItem(
          'setTargetassignmentOBJ',
          JSON.stringify(setTargetassignmentOBJ)
        )
      }

      if (newval === 0) {
        this.rulesForm = {
          templateName: [{
            required: true,
            message: '请输入流程名称',
            trigger: ['blur', 'change']
          }],
          assessment: [{
            required: true,
            validator: this.checkAssessment,
            trigger: ['blur', 'change']
          },
          {
            required: true,
            validator: this.checkAssessment1,
            trigger: ['blur', 'change']
          },
          {
            required: true,
            validator: this.checkAssessment2,
            trigger: ['blur', 'change']
          }

          ],
          assessed: [
            {
              required: true,
              validator: this.checkAssessed,
              trigger: ['blur', 'change']
            },
            {
              required: true,
              validator: this.checkAssessed1,
              trigger: ['blur', 'change']
            },
            {
              required: true,
              validator: this.checkAssessed2,
              trigger: ['blur', 'change']
            }
          ]
        }
        this.$refs['ruleForm'].resetFields()
      } else {
        this.rulesForm = {
          templateName: [{
            required: true,
            message: '请输入流程名称',
            trigger: ['blur', 'change']
          }],
          assessment: [{
            required: true,
            validator: this.checkAssessment,
            trigger: ['blur', 'change']
          },
          {
            required: true,
            validator: this.checkAssessment1,
            trigger: ['blur', 'change']
          },
          {
            required: true,
            validator: this.checkAssessment2,
            trigger: ['blur', 'change']
          }

          ],
          assessed: [
            {
              required: true,
              validator: this.checkAssessed,
              trigger: ['blur', 'change']
            },
            {
              required: true,
              validator: this.checkAssessed1,
              trigger: ['blur', 'change']
            },
            {
              required: true,
              validator: this.checkAssessed2,
              trigger: ['blur', 'change']
            }
          ],
          cc: [{
            required: true,
            validator: this.checkCc,
            trigger: ['blur', 'change']
          }]
        }
      }
    }
  },
  beforeCreate() {
    window.localStorage.removeItem('setTargetassignmentOBJ')
    window.localStorage.removeItem('setAuditnode')
    window.localStorage.removeItem('setSkip')
  },
  created() {
    if (JSON.parse(localStorage.getItem('setTargetassignmentOBJ'))) {
      this.popUpObj = JSON.parse(
        localStorage.getItem('setTargetassignmentOBJ')
      ).popUpObj
      this.ruleForm = JSON.parse(
        localStorage.getItem('setTargetassignmentOBJ')
      ).ruleForm
    } else {
      const setTargetassignmentOBJ = {
        ruleForm: this.ruleForm,
        popUpObj: this.popUpObj
      }
      localStorage.setItem(
        'setTargetassignmentOBJ',
        JSON.stringify(setTargetassignmentOBJ)
      )
    }
    localStorage.setItem('setSkip', JSON.stringify(1)) // 默认自动跳过低等级
  },
  destroyed() {},
  mounted() {},
  methods: {
    // 必填改变选项
    changeComments(val) {
      this.ruleForm.isEnableOpinion = this.ruleForm.isEnableOpinion === val ? 0 : val
      this.approvalKey = !this.approvalKey
      this.$nextTick(() => {
        const setTargetassignmentOBJ = {
          ruleForm: this.ruleForm,
          popUpObj: this.popUpObj
        }
        localStorage.setItem(
          'setTargetassignmentOBJ',
          JSON.stringify(setTargetassignmentOBJ)
        )
        this.$forceUpdate()
      })
    },
    // 修改模版备注
    remarkBlur(e) {
      const setTargetassignmentOBJ = {
        ruleForm: this.ruleForm,
        popUpObj: this.popUpObj
      }
      localStorage.setItem(
        'setTargetassignmentOBJ',
        JSON.stringify(setTargetassignmentOBJ)
      )
    },
    // 修改模版名称
    templateNameBlur(e) {
      const setTargetassignmentOBJ = {
        ruleForm: this.ruleForm,
        popUpObj: this.popUpObj
      }
      localStorage.setItem(
        'setTargetassignmentOBJ',
        JSON.stringify(setTargetassignmentOBJ)
      )
    },
    changeId(id) {
      this.active = id
      const setTargetassignmentOBJ = {
        ruleForm: this.ruleForm,
        popUpObj: this.popUpObj
      }
      localStorage.setItem(
        'setTargetassignmentOBJ',
        JSON.stringify(setTargetassignmentOBJ)
      )
    },
    // 保存
    savaAll() {
      const setAuditnode = JSON.parse(localStorage.getItem('setAuditnode'))
      if (setAuditnode.length < 2) {
        this.$message({
          message: '审批节点至少创建一个',
          type: 'error'
        })
        return false
      } else {
        setAuditnode.map((item, index) => {
          
          if (item.approvalComments === null) {
            this.$message({
              message: `${index}节点有未填项`,
              type: 'error'
            })
            return
          } else if (item.nodeName === '') {
            this.$message({
              message: `${index}节点有未填项`,
              type: 'error'
            })
            return
          } else if (item.commitArray) {
            if (item.commitArray.length < 1) {
              this.$message({
                message: `${index}节点有未填项`,
                type: 'error'
              })
              return
            }
          } else if (item.approver === null) {
            this.$message({
              message: `${index}节点有未填项`,
              type: 'error'
            })
            return
          } else if (item.approver === 0) {
            if (item.approvedby === '') {
              this.$message({
                message: `${index}节点有未填项`,
                type: 'error'
              })
              return
            }
          } else if (item.approver === 1) {
            if (item.approvalRole === '') {
              this.$message({
                message: `${index}节点有未填项`,
                type: 'error'
              })
              return
            }
          } else {
            this.$refs['ruleForm'].validate((valid) => {
              if (valid) {
                let query = {}
                const setTargetassignmentOBJ = JSON.parse(
                  localStorage.getItem('setTargetassignmentOBJ')
                ).ruleForm
                const alllist = JSON.parse(
                  localStorage.getItem('setTargetassignmentOBJ')
                ).popUpObj
                for (const i in setTargetassignmentOBJ) {
                  query[i] = setTargetassignmentOBJ[i]
                }
                query.isAbove = JSON.parse(localStorage.getItem('setSkip'))
                query.flowNodeinfoVos = []
                query.assessDepartUserInfos = [] // 考核 部门
                query.assessRoleUserInfos = [] // 考核 角色
                query.assessUserInfos = [] // 考核 人员
                query.beingAssessDepartUserInfos = [] // 被考核部门
                query.beingAssessRoleUserInfos = [] // 被考核角色
                query.beingAssessUserInfos = [] // 被考核人员
                query.ccRoleList = [] // 抄送角色数组
                query.ccPersonnelList = [] // 抄送人员数组
                const setAuditnode = JSON.parse(
                  localStorage.getItem('setAuditnode')
                )

                setAuditnode.map((item) => {
                  if (item.id !== 0) {
                    item.commitArray.forEach((e) => {
                      for (const key in e) {
                        if (key === 'title') {
                          e['nodeHandler'] = e[key]
                          delete e[key]
                        }
                      }
                    })

                    console.log('item', item)
                    query.flowNodeinfoVos.push({
                      nodeName: item.nodeName,
                      nodeHandler: item.approvedby === ''
                        ? item.approvalRole
                        : item.approvedby,
                      approvalType: item.approver,
                      isEnableOpinion: item.isEnableOpinion,
                      setpId: item.id,
                      sevent: item.sevent,
                      content: item.content,
                      span: item.span,
                      flowNodeHandlers: item.commitArray
                    })
                  }
                })
                alllist.map((item) => {
                  item.commitArray.map((it) => {
                    if (item.type === '1') {
                      query.assessDepartUserInfos.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    } else if (item.type === '2') {
                      query.assessRoleUserInfos.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    } else if (item.type === '3') {
                      query.assessUserInfos.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    } else if (item.type === '4') {
                      query.beingAssessDepartUserInfos.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    } else if (item.type === '5') {
                      query.beingAssessRoleUserInfos.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    } else if (item.type === '6') {
                      query.beingAssessUserInfos.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    } else if (item.type === '9') {
                      query.ccRoleList.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    } else if (item.type === '10') {
                      query.ccPersonnelList.push({
                        userRoleId: it.nodeHandlerId,
                        userRoleName: it.title
                      })
                    }
                  })
                })

                query = JSON.stringify(query)
                this.$Http
                  .setNewProcess(query)
                  .then((res) => {
                    if (res.code === 200) {
                      this.$message({
                        type: 'success',
                        message: '创建成功!'
                      })
                      window.localStorage.removeItem('setTargetassignmentOBJ')
                      window.localStorage.removeItem('setAuditnode')
                      window.localStorage.removeItem('setSkip')
                      this.$router.go(-1)
                    } else {
                      this.$message({
                        type: 'error',
                        message: res.message
                      })
                    }
                  })
                  .catch((err) => {
                    console.log('err', err)
                  })
              } else {
                this.$message({
                  message: '有必填信息未完成,请先完成再保存!',
                  type: 'error'
                })
                return false
              }
            })
          }
        })
      }
    },
    // 删除
    deleteEach(index) {
      if (index === 0) {
        this.ruleForm.assessDepartName = ''
      } else if (index === 1) {
        this.ruleForm.assessRoleName = ''
      } else if (index === 2) {
        this.ruleForm.assessUserName = ''
      } else if (index === 3) {
        this.ruleForm.beingAssessDepartName = ''
      } else if (index === 4) {
        this.ruleForm.beingAssessRoleName = ''
      } else if (index === 5) {
        this.ruleForm.beingAssessUserName = ''
      } else if (index === 6) {
        this.ruleForm.ccRole = ''
      } else if (index === 7) {
        this.ruleForm.ccPersonnel = ''
      }
      this.popUpObj[index].commitArray = []
      const setTargetassignmentOBJ = {
        ruleForm: this.ruleForm,
        popUpObj: this.popUpObj
      }
      localStorage.setItem(
        'setTargetassignmentOBJ',
        JSON.stringify(setTargetassignmentOBJ)
      )
    },
    // 点击弹窗
    popUpClick(index) {
      this.popUpIndex = index
      this.popUpObj[this.popUpIndex].show = true
    },
    // 弹窗确定
    handleDetermine(str, newarr, index) {
      if (index === 0) {
        this.ruleForm.assessDepartName = str
      } else if (index === 1) {
        this.ruleForm.assessRoleName = str
      } else if (index === 2) {
        this.ruleForm.assessUserName = str
      } else if (index === 3) {
        this.ruleForm.beingAssessDepartName = str
      } else if (index === 4) {
        this.ruleForm.beingAssessRoleName = str
      } else if (index === 5) {
        this.ruleForm.beingAssessUserName = str
      } else if (index === 6) {
        this.ruleForm.ccRole = str
      } else if (index === 7) {
        this.ruleForm.ccPersonnel = str
      }
      this.popUpObj[index].show = false
      this.popUpObj[index].commitArray = newarr
      if (JSON.parse(localStorage.getItem('setTargetassignmentOBJ'))) {
        const setTargetassignmentOBJ = JSON.parse(
          localStorage.getItem('setTargetassignmentOBJ')
        )
        setTargetassignmentOBJ.popUpObj.map((it, inx) => {
          if (index === inx) {
            it.commitArray = newarr
          }
        })
        setTargetassignmentOBJ.ruleForm = this.ruleForm

        localStorage.setItem(
          'setTargetassignmentOBJ',
          JSON.stringify(setTargetassignmentOBJ)
        )
      }
    },
    // 关闭弹窗
    handleClose(index) {
      this.popUpObj[index].show = false
    }
  }
}
</script>
<style lang="scss" scoped>
  ::v-deep .clearPadding .vxe-cell {
    padding: 0;
  }

  ::v-deep .clearPaddingLeft .vxe-cell {
    padding-left: 0px;
  }

  ::v-deep {
    .main-el-switch {
      position: relative;

      .el-switch__core {
        height: 24px;
        border-radius: 12px;

        &:after {
          left: 4px;
          top: 3px;
        }
      }

      &.el-switch {
        &.is-checked {
          .el-switch__core {
            &:after {
              margin-left: -20px;
              left: 100%;
            }
          }
        }
      }

      &.is-checked {
        .el-switch__label--left {
          opacity: 0;
        }

        .el-switch__label--right {
          opacity: 1;
        }
      }

      .el-switch__label {
        position: absolute;
        top: 0;
      }

      .el-switch__label--left {
        right: 0;
        color: #999;
        z-index: 1;
        margin-right: 8px;
      }

      .el-switch__label--right {
        left: 0;
        color: #fff;
        opacity: 0;
        margin-left: 8px;
      }
    }
  }
</style>

<style lang="scss" scoped>
  .container {
    padding: 10px 10px 0 10px;
    box-sizing: border-box;

    .step-box {
      .btnbox {
        text-align: right;
      }
    }

    .container_form {
      .item {
        margin-top: 10px;
        display: flex;
        align-items: center;

      }
    }

  }
</style>
